/**
 * 武汉天瑞兴科技有限公司
 */
package com.adds.lvds.controller.organize;

import java.util.List;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.adds.lvds.security.acegi.utils.CurrentUserUtils;
import com.adds.lvds.security.model.SysCurrentUser;
import com.adds.lvds.service.impl.organize.OrganizeTreeService;

/**
 * 项目名称 ：lvds-web-controller
 * 
 * @author zhangjian
 * @time 2017-11-23下午4:12:09
 */
@Controller
@RequestMapping("/orgTree/")
public class SysOrgTreeController {
	@Inject
	private OrganizeTreeService organizeTreeService;

	@ResponseBody
	@RequestMapping(value = "getOrgJson")
	public List<Object> getOrgJson(HttpServletRequest request,
			HttpServletResponse response,
			@Param(value = "user_id") String user_id) throws Exception {
		// 异步加载请求的节点id，第一次加载默认当前用户所在的机构id
		String Org_id = request.getParameter("id");
		// 判断当前用户是否admin，如果Org_id位空默认1，显示全省数据
		SysCurrentUser sysCurrentUser = CurrentUserUtils
				.currentUser(request);
		boolean initFlag = false;
		//初始化时 Org_id为空
		if (StringUtils.isEmpty(Org_id)) {
			initFlag = true;
			if("admin".equals(sysCurrentUser.getUserName())){
				Org_id = "1";
			}else{
				if(sysCurrentUser.getSysUserPermission()!= null){
					Org_id = String.valueOf(sysCurrentUser.getSysUserPermission().getOrg_id());
				}
			}
		
		}
		List<Object> list = organizeTreeService.getOrgJson(user_id, Org_id, initFlag);
		return list;
	}

	
}
